package com.wkm.chainchain.pbft.common;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolExecutor {
    /**
     * 定义一个当前节点的线程池
     * 经过实验 网络中在刚开始线程会达到峰值 200-1200 在大量消息被消费后 线程多数时间维持在1-10左右
     * 除非消息发送客户端一直发送消息
     * 注意: 虚拟机栈的内存给的越大, 可以创建的线程数越少 详见 https://blog.csdn.net/weixin_37646636/article/details/120059177
     */
    public static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            2000,
            2000,
            2,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(1),
            new ThreadPoolExecutor.CallerRunsPolicy());
}
